www.gusucode.com > VC++ 酒店管理系统-源码程序 > VC++ 酒店管理系统-源码程序/code/hotel2003/CheckOut.cpp

    //Download by http://www.NewXing.com
// CheckOut.cpp : implementation file
//

#include "stdafx.h"
#include "qq.h"
#include "CheckOut.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCheckOut dialog
int CCheckOut::year=0;
int CCheckOut::month=0;
int CCheckOut::day=0;
int CCheckOut::hour=0;
int CCheckOut::minute=0;
int CCheckOut::second=0;
CString CCheckOut::STRINGS[100]={""};
CCheckOut::CCheckOut(CWnd* pParent /*=NULL*/)
	: CDialog(CCheckOut::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCheckOut)
	//}}AFX_DATA_INIT
	
}


void CCheckOut::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCheckOut)
	DDX_Control(pDX, IDC_CHECKOUT_BILLCODE, BillCode);
	DDX_Control(pDX, IDC_CHECKOUT_HANDCODE, HandCode);
	DDX_Control(pDX, IDC_CHECKOUT_CURTIME, CurTime);
	DDX_Control(pDX, IDC_CHECKOUT_TIMES, Times);
	DDX_Control(pDX, IDC_CHECKOUT_SUM, Sum);
	DDX_Control(pDX, IDC_CHECKOUT_SUBMONEY, SubMoney);
	DDX_Control(pDX, IDC_CHECKOUT_STARTTIME, StartTime);
	DDX_Control(pDX, IDC_CHECKOUT_PAID, Paid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCheckOut, CDialog)
	//{{AFX_MSG_MAP(CCheckOut)
	ON_CBN_EDITCHANGE(IDC_CHECKOUT_HANDCODE, OnEditchangeCheckoutHandcode)
	ON_EN_CHANGE(IDC_CHECKOUT_PAID, OnChangeCheckoutPaid)
	ON_CBN_SELCHANGE(IDC_CHECKOUT_HANDCODE, OnSelchangeCheckoutHandcode)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCheckOut message handlers
BOOL CCheckOut::OnInitDialog() 
{
	CDialog::OnInitDialog();
	HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
	this->SetIcon(m_hIcon,true);//设置对话框图标
	// TODO: Add extra initialization here
	///安装匹配字符串
	InitDate();//初始化数组 
	m_acCombo.Init(GetDlgItem(IDC_CHECKOUT_HANDCODE));
	if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
	{
		MessageBox("查询数据库失败或者数据库没有连接!",
			       "数据库错误",
				   MB_OK
				   );
		return false;
	}

	m_GuestInfoSet.MoveFirst();//move to the first record
	int i=0;
    while(!m_GuestInfoSet.IsEOF())
	{
        STRINGS[i]=m_GuestInfoSet.m_HandCode;
        m_GuestInfoSet.MoveNext();
		i++;
	}
    m_GuestInfoSet.Close();//关闭数据库
    for (int j=0; (!STRINGS[j].IsEmpty()); j++)
	{
		m_acCombo.GetStringList().Add(STRINGS[j].GetBuffer(STRINGS[j].GetLength()));
	}
	//产生帐单号码
	CCreateBillCode billcode;
	BillCode.SetWindowText(billcode.GenereBillCodeForCheckOut());
    Sum.SetWindowText("0");
	Paid.SetWindowText("0");
	SubMoney.SetWindowText("0");
    Times.SetWindowText("0");
	//设置当前时间

    CTime time=CTime::GetCurrentTime();//构造时间对象
    CTime tm(time);
    year=tm.GetYear();
    month=tm.GetMonth();
	day=tm.GetDay();
	hour=tm.GetHour();
	minute=tm.GetMinute();
	second=tm.GetSecond();
	CString strYear,strMonth,strDay,strHour,strMinute,strSecond;
	strYear.Format("%d",year);
	strMonth.Format("%d",month);
	strDay.Format("%d",day);
	strHour.Format("%d",hour);
	strMinute.Format("%d",minute);
	strSecond.Format("%d",second);
	CString strShowText;
	strShowText=strYear+"-"+strMonth+"-"+strDay;
    strShowText=strShowText+" "+strHour+":"+strMinute+":"+strSecond;
    CurTime.SetWindowText(strShowText);


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCheckOut::OnSelchangeCheckoutHandcode() 
{
	// TODO: Add your control notification handler code here
	    Sum.SetWindowText("0");
		Paid.SetWindowText("0");
		SubMoney.SetWindowText("0");
        CString strHandCode="";
		HandCode.GetLBText(HandCode.GetCurSel(),strHandCode);

			//到数据库中查找是否存在这个记录
				int Startyear=0;  //得到年份
				int Startmonth=0; 
				int Startday=0;
				int Starthour=0;
				int Startmini=0;
				int Startsecond=0;
				float nRoomPrice=0.00f;//房间的价格(total)
//////////////////////////////////////////////////////////////////////////
/*############### 显示开始入住时间的查询过程 ##################*/
	if(!m_BillCheckoutInfoSet.Open())
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return;
	}
	m_BillCheckoutInfoSet.MoveFirst();//移动到第一条记录
	while (!m_BillCheckoutInfoSet.IsEOF())
	{
		if(strHandCode==m_BillCheckoutInfoSet.m_HandCode)
		{//找到了这个手牌号码,将这个记录中的开始时间写道对话框中
			CTime strTime=m_BillCheckoutInfoSet.m_StartTime;
            CString strTimeShow,strYear,strMonth,strDay,strHour,strMinute,strSecond;
			Startyear=strTime.GetYear();  //得到年份
		    Startmonth=strTime.GetMonth();
			Startday=strTime.GetDay();
			Starthour=strTime.GetHour();
			Startmini=strTime.GetMinute();
			Startsecond=strTime.GetSecond();
			strYear.Format("%d",Startyear);//格式化年份
			strMonth.Format("%d",Startmonth);
			strDay.Format("%d",Startday);
			strHour.Format("%d",Starthour);
			strMinute.Format("%d",Startmini);
			strSecond.Format("%d",Startsecond);//格式化秒
			strTimeShow=strYear+"-"+strMonth+"-"+strDay+" "+strHour
				+":"+strMinute+":"+strSecond;
			StartTime.SetWindowText(strTimeShow);
/////////////////////////////////////////////////////////////////
	        //计算入住的总时间
	        CString strStartTime,strEndTime;
	        long nHours=0,nMinutes=0;
	        StartTime.GetWindowText(strStartTime); //得到开始入住的时间
	        CurTime.GetWindowText(strEndTime);//得到当前的时间
	        if(strStartTime=="")
			{
                 Times.SetWindowText("");
			}
            int dYears=0,dMonths=0,dDays=0,dMinutes=0,dHours=0,dSeconds=0;
	        dYears=year-Startyear;//得到年份的差值
	        dMonths=month-Startmonth;
	        dDays=day-Startday;
	        dHours=hour-Starthour;
	        dMinutes=minute-Startmini;
	        dSeconds=second-Startsecond;
	        //计算总的时间差
			nHours=dYears*365*24+dMonths*30*24+dDays*24+dHours;
	        nMinutes=dMinutes+(int)dSeconds/60;
	        if(nMinutes<0)
			{
		        nHours=nHours-1;
		        nMinutes=nMinutes+60;
			}
	        CString strHours,strMinutes;
	        strHours.Format("%d",nHours);
	        strMinutes.Format("%d",nMinutes);
	        CString strTimes;
	        strTimes=strHours+":"+strMinutes;
	        Times.SetWindowText(strTimes);
            /*      通过手牌号码查找房间的号码      */
			
			if(!m_GuestInfoSet.Open())
			{
				MessageBox("打开数据库失败!","数据库错误",MB_OK);
				return;
			}
			m_GuestInfoSet.MoveFirst();//移动到第一条记录
			while (!m_GuestInfoSet.IsEOF())
			{
				if(strHandCode==m_GuestInfoSet.m_HandCode)
				{//查找到相应的手牌号码
                    CString strRoomCode;
					strRoomCode=m_GuestInfoSet.m_RoomCode;//得到房间号码
					char* s=strRoomCode.GetBuffer(strRoomCode.GetLength());
					char* strTokText=strtok(s,",");
                    
					/*   通过查找得到的房间号码查看房间的价格   */
					while(strTokText!=NULL)
					{
					    CString strRoomCodeTok=strTokText;//得到房间号码
						if(!m_RoomInfoSet.Open())
						{//打开房间表
							MessageBox("打开数据库失败!","数据库错误",MB_OK);
							return;
						}
						m_RoomInfoSet.MoveFirst();//移动第一条记录
						while(!m_RoomInfoSet.IsEOF())
						{
							if(m_RoomInfoSet.m_RoomCode==strRoomCode)
							{//找到了房间查看房间的价格
								//将当前查找到的房间价格加入到总和中
								nRoomPrice=nRoomPrice+m_RoomInfoSet.m_Price;
							}
							m_RoomInfoSet.MoveNext();//移动到下一条记录
						}
						m_RoomInfoSet.Close();//查询完毕关闭数据库
						//得到下一个房间号码
						strTokText=strtok(NULL,",");
					}
				}
				m_GuestInfoSet.MoveNext();//移动到客人的下一条记录
			}
			m_GuestInfoSet.Close();//关闭客人信息表
			/////////计算住房间的费用
			////计算方法为:房间费用=房间的价格*住的时间
			float nRoomTotalPrice=0.00f;
			/*        
			          计算客人住房所用的总费用
			*/
			nRoomTotalPrice=(float)(nHours+(float)nMinutes/60)*nRoomPrice;

			/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
 /*
                   开始计算客人在酒店期间各种消费总数目
 */
             /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
			             通过查找帐单来计算总的消费费用
			   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
			long nSumInCast=0;//消费的总费用
            if(!m_BillInfoSet.Open())
			{
				MessageBox("打开数据库失败!","数据库错误",MB_OK);
				return;
			}
			m_BillInfoSet.MoveFirst();//first
			while (!m_BillInfoSet.IsEOF())
			{
				if(strHandCode==m_BillInfoSet.m_HandCode)
				{
					nSumInCast=nSumInCast+m_BillInfoSet.m_Sum-m_BillInfoSet.m_Paid;
				}
				m_BillInfoSet.MoveNext();//移动到下一条记录
			}
			m_BillInfoSet.Close();//关闭数据库
	  /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
			  计算客人总的费用包括房间的钱和消费的钱
	  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
            CString strSum;
			strSum.Format("%6.00f",nSumInCast+nRoomTotalPrice);
			Sum.SetWindowText(strSum);
		/*
			//更新找钱窗口的数据
		*/
			OnChangeCheckoutPaid();
			break;
		}
		else
		{
             StartTime.SetWindowText("");
             Times.SetWindowText("0");
			 Sum.SetWindowText("0");
		}
		m_BillCheckoutInfoSet.MoveNext();//移动到下一条记录
	}
	m_BillCheckoutInfoSet.Close();//关闭数据库
/*######################    END    ############################*/

}


void CCheckOut::OnEditchangeCheckoutHandcode() 
{
	// TODO: Add your control notification handler code here
	//清除前面的记录,重新进行计算

	CString strHandCode="";
	HandCode.GetWindowText(strHandCode);//得到当前的手牌号码
	//到数据库中查找是否存在这个记录
				int Startyear=0;  //得到年份
				int Startmonth=0; 
				int Startday=0;
				int Starthour=0;
				int Startmini=0;
				int Startsecond=0;
				float nRoomPrice=0.00f;//房间的价格(total)
//////////////////////////////////////////////////////////////////////////
/*############### 显示开始入住时间的查询过程 ##################*/
	if(!m_BillCheckoutInfoSet.Open())
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return;
	}
	m_BillCheckoutInfoSet.MoveFirst();//移动到第一条记录
	while (!m_BillCheckoutInfoSet.IsEOF())
	{
		if(strHandCode==m_BillCheckoutInfoSet.m_HandCode)
		{//找到了这个手牌号码,将这个记录中的开始时间写道对话框中
			CTime strTime=m_BillCheckoutInfoSet.m_StartTime;
            CString strTimeShow,strYear,strMonth,strDay,strHour,strMinute,strSecond;
			Startyear=strTime.GetYear();  //得到年份
		    Startmonth=strTime.GetMonth();
			Startday=strTime.GetDay();
			Starthour=strTime.GetHour();
			Startmini=strTime.GetMinute();
			Startsecond=strTime.GetSecond();
			strYear.Format("%d",Startyear);//格式化年份
			strMonth.Format("%d",Startmonth);
			strDay.Format("%d",Startday);
			strHour.Format("%d",Starthour);
			strMinute.Format("%d",Startmini);
			strSecond.Format("%d",Startsecond);//格式化秒
			strTimeShow=strYear+"-"+strMonth+"-"+strDay+" "+strHour
				+":"+strMinute+":"+strSecond;
			StartTime.SetWindowText(strTimeShow);
/////////////////////////////////////////////////////////////////
	        //计算入住的总时间
	        CString strStartTime,strEndTime;
	        long nHours=0,nMinutes=0;
	        StartTime.GetWindowText(strStartTime); //得到开始入住的时间
	        CurTime.GetWindowText(strEndTime);//得到当前的时间
	        if(strStartTime=="")
			{
                 Times.SetWindowText("");
			}
            int dYears=0,dMonths=0,dDays=0,dMinutes=0,dHours=0,dSeconds=0;
	        dYears=year-Startyear;//得到年份的差值
	        dMonths=month-Startmonth;
	        dDays=day-Startday;
	        dHours=hour-Starthour;
	        dMinutes=minute-Startmini;
	        dSeconds=second-Startsecond;
	        //计算总的时间差
			nHours=dYears*365*24+dMonths*30*24+dDays*24+dHours;
	        nMinutes=dMinutes+(int)dSeconds/60;
	        if(nMinutes<0)
			{
		        nHours=nHours-1;
		        nMinutes=nMinutes+60;
			}
	        CString strHours,strMinutes;
	        strHours.Format("%d",nHours);
	        strMinutes.Format("%d",nMinutes);
	        CString strTimes;
	        strTimes=strHours+":"+strMinutes;
	        Times.SetWindowText(strTimes);
            /*      通过手牌号码查找房间的号码      */
			
			if(!m_GuestInfoSet.Open())
			{
				MessageBox("打开数据库失败!","数据库错误",MB_OK);
				return;
			}
			m_GuestInfoSet.MoveFirst();//移动到第一条记录
			while (!m_GuestInfoSet.IsEOF())
			{
				if(strHandCode==m_GuestInfoSet.m_HandCode)
				{//查找到相应的手牌号码
                    CString strRoomCode;
					strRoomCode=m_GuestInfoSet.m_RoomCode;//得到房间号码
					char* s=strRoomCode.GetBuffer(strRoomCode.GetLength());
					char* strTokText=strtok(s,",");
                    
					/*   通过查找得到的房间号码查看房间的价格   */
					while(strTokText!=NULL)
					{
					    CString strRoomCodeTok=strTokText;//得到房间号码
						if(!m_RoomInfoSet.Open())
						{//打开房间表
							MessageBox("打开数据库失败!","数据库错误",MB_OK);
							return;
						}
						m_RoomInfoSet.MoveFirst();//移动第一条记录
						while(!m_RoomInfoSet.IsEOF())
						{
							if(m_RoomInfoSet.m_RoomCode==strRoomCode)
							{//找到了房间查看房间的价格
								//将当前查找到的房间价格加入到总和中
								nRoomPrice=nRoomPrice+m_RoomInfoSet.m_Price;
							}
							m_RoomInfoSet.MoveNext();//移动到下一条记录
						}
						m_RoomInfoSet.Close();//查询完毕关闭数据库
						//得到下一个房间号码
						strTokText=strtok(NULL,",");
					}
				}
				m_GuestInfoSet.MoveNext();//移动到客人的下一条记录
			}
			m_GuestInfoSet.Close();//关闭客人信息表
			/////////计算住房间的费用
			////计算方法为:房间费用=房间的价格*住的时间
			float nRoomTotalPrice=0.00f;
			/*        
			          计算客人住房所用的总费用
			*/
			nRoomTotalPrice=(float)(nHours+(float)nMinutes/60)*nRoomPrice;

			/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */

 /*
                   开始计算客人在酒店期间各种消费总数目
 */
             /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
			             通过查找帐单来计算总的消费费用
			   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
			long nSumInCast=0;//消费的总费用
            if(!m_BillInfoSet.Open())
			{
				MessageBox("打开数据库失败!","数据库错误",MB_OK);
				return;
			}
			m_BillInfoSet.MoveFirst();//first
			while (!m_BillInfoSet.IsEOF())
			{
				if(strHandCode==m_BillInfoSet.m_HandCode)
				{
					nSumInCast=nSumInCast+m_BillInfoSet.m_Sum-m_BillInfoSet.m_Paid;
				}
				m_BillInfoSet.MoveNext();//移动到下一条记录
			}
			m_BillInfoSet.Close();//关闭数据库
	  /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
			  计算客人总的费用包括房间的钱和消费的钱
	  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
            CString strSum;
			strSum.Format("%6.00f",nSumInCast+nRoomTotalPrice);
			Sum.SetWindowText(strSum);
		/*
			//更新找钱窗口的数据
		*/
			OnChangeCheckoutPaid();
			break;
		}
		else
		{
             StartTime.SetWindowText("");
             Times.SetWindowText("0");
			 Sum.SetWindowText("0");
		}
		m_BillCheckoutInfoSet.MoveNext();//移动到下一条记录
	}
	m_BillCheckoutInfoSet.Close();//关闭数据库
/*######################    END    ############################*/
}

void CCheckOut::OnChangeCheckoutPaid() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strSum,strPaid;
	Sum.GetWindowText(strSum);
	Paid.GetWindowText(strPaid);
    long nSum=0,nPaid=0,nSub=0;
	char* sSum,*sPaid;
	sSum=strSum.GetBuffer(strSum.GetLength());
	sPaid=strPaid.GetBuffer(strPaid.GetLength());
	nSum=atol(sSum);
	nPaid=atol(sPaid);
	nSub=nPaid-nSum;
	CString strSub;
 	strSub.Format("%ld",nSub);
    SubMoney.SetWindowText(strSub);
}

void CCheckOut::OnOK() 
{
	// TODO: Add extra validation here
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                      保存数据到数据库中
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
	
	CString strEndTime,strSum,strHandCode;
	HandCode.GetWindowText(strHandCode);//手牌号码
    CurTime.GetWindowText(strEndTime);//得到当前时间,也就是结束时间
	Sum.GetWindowText(strSum);
    
    ///////将结束实际写到数据库中
	if(!m_BillCheckoutInfoSet.Open())
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return;
	}
	m_BillCheckoutInfoSet.MoveFirst();
	while (!m_BillCheckoutInfoSet.IsEOF())
	{
		if(strHandCode==m_BillCheckoutInfoSet.m_HandCode)
		{
			if(!m_BillCheckoutInfoSet.m_Sum.IsEmpty())
			{//已经写了这个记录
				MessageBox("该客户已经结帐了!","结帐错误",MB_OK);
				m_BillCheckoutInfoSet.Close();//关闭数据库停止查找
				return;
			}
			else
			{
				CTime tm(year,month,day,hour,minute,second);
				m_BillCheckoutInfoSet.Edit();
				m_BillCheckoutInfoSet.m_EndTime=tm;
				m_BillCheckoutInfoSet.m_Sum=strSum;
			    m_BillCheckoutInfoSet.Update();
			}
		}
		m_BillCheckoutInfoSet.MoveNext();
	}
	m_BillCheckoutInfoSet.Close();
	InitDate();//初始化数组
	CDialog::OnOK();
}

void CCheckOut::InitDate()
{
	for(int i=0;i<100;i++)
	{
		STRINGS[i]="";
	}
}



void CCheckOut::OnCancel() 
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();
}